package com.fuint.common.config;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fuint.minio.minIOConst.BucketConst;
import com.fuint.minio.service.MinIOService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
public class ApplicationStartupListener implements CommandLineRunner{
	private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupListener.class);
	
	@Autowired
	private RedisProperties redisProperties;
	@Autowired
	private DataSourceProperties dataSourceProperties;
	@Autowired
	private MinIOService minIOService;

	@Override
	public void run(String... args) throws Exception {
		logger.info("===========================springboot 启动完成==========================");
		logger.info("redis配置如下：host:{},port:{}",redisProperties.getHost(),redisProperties.getPort());
		logger.info("数据库配置如下：host:{}",dataSourceProperties.getUrl());
		logger.info("程序启动中，当前时间：{}", DateUtil.now());
		logger.info("=======================================================================");
		//fastjson:关闭循环引用策论
		JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.DisableCircularReferenceDetect.getMask();

		// 创建默认原始数据bucket
		minIOService.initBucket(BucketConst.FUNINT_BUCKET,false,true);
	}

}
